<?php

if( !function_exists("customizedUpdateOption") )
{
	function customizedUpdateOption($option_name, $new_value)
	{
		$base= 'zzMYAN_';
		$option_name = $base . $option_name;
		$new_value = urlencode($new_value);
		
		if ( get_option( $option_name ) != $new_value ) {
			update_option( $option_name, $new_value );
		} else {
			$deprecated = ' ';
			$autoload = 'no';
			add_option( $option_name, $new_value, $deprecated, $autoload );
		}
		
	}
}

if( !function_exists("themeGetOption") )
{
	function themeGetOption($option_name)
	{
		$base= 'zzMYAN_';
		$option_name = $base . $option_name;
		return urldecode(get_option( $option_name ));
	}
}

//page.php, single.php (related post php link), 
if( !function_exists("get_absolute_template_path")){
	// This function does not end with / symbol
	function get_absolute_template_path(){
		$templatePath= get_theme_root()."/".get_template();
		$templatePath= str_replace("\\","/",$templatePath);
		return $templatePath;
	}
}

// admin panel => quote.php, comments.php
if( !function_exists("convertNewlineToBRcode")){
	function convertNewlineToBRcode($text){
		return str_replace("\n","<BR/>",$text);
	}
}

function arphabet_widgets_init() {

	register_sidebar( array(
		'name' => 'Home right sidebar',
		'id' => 'home_right_1',
		'before_widget' => '<div class="sidebar_data">',
		'after_widget' => '</div>',
		'before_title' => '<h2 class="rounded">',
		'after_title' => '</h2>',
	) );
}
add_action( 'widgets_init', 'arphabet_widgets_init' );

function myan_sitemap_callback() {
	$cats = get_categories('exclude=');
	echo '<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
	foreach ($cats as $cat) 
	{
		//echo $cat->cat_name;
		$archive_query = new WP_Query('posts_per_page=-1&order=asc&orderby=title&cat='.$cat->cat_ID);
		while ($archive_query->have_posts()) 
		{
			echo "<url>";
			$archive_query->the_post();
			$category = get_the_category();
			//echo '<loc><li><a href="'.get_permalink().'" title="'.get_the_title().'">'.get_the_title().'</a></li></loc>';
			echo  '<loc>'.get_permalink().'</loc>';
			echo '<lastmod>'.get_the_modified_date('c').'</lastmod>';
			echo "</url>";
		}
	}
	echo '</urlset>';
	die;
}

add_action( 'publish_post', 'notify_new_post' );
function notify_new_post($post_id) {
	if(! wp_get_schedule('notify_google_sitemap'))
	{
		wp_schedule_single_event( time() + 3600, 'notify_google_sitemap' );
	}
	return $post_id;
}

add_action( 'notify_google_sitemap','notify_google_sitemap');
function notify_google_sitemap() {
	$url = "http://www.google.com/webmasters/tools/ping?sitemap=" . urlencode(get_bloginfo('url').'?sitemap=view');
	@file_get_contents($url);
}



add_filter( 'dashboard_glance_items', 'custom_glance_items', 10, 1 );
function custom_glance_items( $items = array() ) {
	$time = wp_next_scheduled('notify_google_sitemap');
	if($time != '')
		echo "<li class='dashicons-before dashicons-admin-tools'><strong>Sitemap submission:</strong> " . date("D, G:i:s, j.M.Y, T", $time).'</li>';
	return $items;
}

add_theme_support('post-thumbnails');
//set_post_thumbnail_size(980,150,true);

/* carried over from 2.7*/
add_action('admin_menu', 'myan_plugin_menu');

function myan_plugin_menu() {
		
	add_menu_page("Mythic- Admin- Options", "Admin || Tools", 'manage_categories', 'myan-top-level-handle', 'myan_sublevel_banner_extendedForError' );
	// Add a submenu to the custom top-level menu:

	// Add a submenu to the custom top-level menu:
    add_submenu_page('myan-top-level-handle', "Set banner image", "Banner image", 'manage_categories', 'myan-top-level-handle', 'myan_sublevel_banner');

	// manage_options = Administrator; manage_categories = Editor; publish_posts = Author;
	// Add a submenu to the custom top-level menu:
    add_submenu_page('myan-top-level-handle', "Editor inputs", "Editor inputs", 'manage_categories', 'myan-sub-editor-input', 'myan_sublevel_editor_input');
	// Add a submenu to the custom top-level menu:
    add_submenu_page('myan-top-level-handle', "User Variables", "Admin inputs", 'manage_categories', 'myan-sub-userVariableManagement', 'myan_sublevel_userVariableManagement');
	// Add a submenu to the custom top-level menu:
    add_submenu_page('myan-top-level-handle', "Set youtube link", "Youtube link", 'manage_categories', 'myan-sub-youtube', 'myan_sublevel_youtube');
	// Add a submenu to the custom top-level menu:
    //add_submenu_page('myan-top-level-handle', "Generic post import", "Generic post import", 'publish_posts', 'myan-sub-facebook-import', 'myan_sublevel_facebook_import');
	
	
	add_submenu_page('myan-top-level-handle', "Sitemap", "Sitemap", 'manage_categories', 'myan-sub-sitemap', 'myan_sublevel_sitemap');
}

function myan_sublevel_sitemap(){
	echo "<h1>Sitemap url</h1>";
	$url = get_bloginfo('url').'?sitemap=view';
	echo "<a href='$url' target=_blank>$url</a>";
}


function myan_sublevel_banner_extendedForError()
{
	;
}

function myan_sublevel_youtube()
{
	include_once("admin.panel/youtube.php");
	execute_LSDFHEWOR327489329CNVSEKL();
}

function myan_sublevel_userVariableManagement()
{
	include_once("admin.panel/userVariableManagement.php");
	execute_ZXKCSEIRLSDKMSEKFL('myan-sub-userVariableManagement');
}


function myan_sublevel_highlighted()
{
	include_once("admin.panel/highlighted.php");
}

function myan_sublevel_banner()
{
	include_once("admin.panel/banner.php");
	execute_XCVKSEUIXLDKVASJ('myan-top-level-handle');
}

// basically for panaorama pic link but replaced with quote to code less
function myan_sublevel_editor_input()
{
	include_once("admin.panel/quote.php");
	execute_DVCKEWERPD7359FNZLXJG('myan-sub-editor-input');
}


/*
// Hook for adding admin menus
//add_action('admin_menu', 'mt_add_pages');

// action function for above hook
function mt_add_pages() {
    // Add a new submenu under Settings:
    add_options_page(__('Test Settings','menu-test'), __('Test Settings','menu-test'), 'manage_options', 'testsettings', 'mt_settings_page');

    // Add a new submenu under Tools:
    add_management_page( __('Test Tools','menu-test'), __('Test Tools','menu-test'), 'manage_options', 'testtools', 'mt_tools_page');

    // Add a new top-level menu (ill-advised):
    add_menu_page(__('Test Toplevel','menu-test'), __('Test Toplevel','menu-test'), 'manage_options', 'mt-top-level-handle', 'mt_toplevel_page' );

    // Add a submenu to the custom top-level menu:
    add_submenu_page('mt-top-level-handle', __('Test Sublevel','menu-test'), __('Test Sublevel','menu-test'), 'manage_options', 'sub-page', 'mt_sublevel_page');

    // Add a second submenu to the custom top-level menu:
    add_submenu_page('mt-top-level-handle', __('Test Sublevel 2','menu-test'), __('Test Sublevel 2','menu-test'), 'manage_options', 'sub-page2', 'mt_sublevel_page2');
}

// mt_settings_page() displays the page content for the Test settings submenu
function mt_settings_page() {
    echo "<h2>" . __( 'Test Settings', 'menu-test' ) . "</h2>";
}

// mt_tools_page() displays the page content for the Test Tools submenu
function mt_tools_page() {
    echo "<h2>" . __( 'Test Tools', 'menu-test' ) . "</h2>";
}

// mt_toplevel_page() displays the page content for the custom Test Toplevel menu
function mt_toplevel_page() {
    echo "<h2>" . __( 'Test Toplevel', 'menu-test' ) . "</h2>";
}

// mt_sublevel_page() displays the page content for the first submenu
// of the custom Test Toplevel menu
function mt_sublevel_page() {
    echo "<h2>" . __( 'Test Sublevel', 'menu-test' ) . "</h2>";
}

// mt_sublevel_page2() displays the page content for the second submenu
// of the custom Test Toplevel menu
function mt_sublevel_page2() {
    echo "<h2>" . __( 'Test Sublevel2', 'menu-test' ) . "</h2>";
}
*/

?>